import 'package:common/common.dart';

/// 自定义选中控件
class AppCheckbox extends StatelessWidget {
  final bool value;

  final ValueChanged<bool> onChanged;

  final Widget? selected;
  final Widget? unselected;

  final Color? selectedColor;
  final Color? unselectedColor;

  const AppCheckbox(
      {Key? key, required this.value, required this.onChanged, this.selected, this.unselected, this.selectedColor, this.unselectedColor})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final child = value ? selected ?? _buildChild(value) : unselected ?? _buildChild(value);
    return GestureDetector(child: child, onTap: () => onChanged.call(value));
  }

  Widget _buildChild(bool value) {
    return Container(
        padding: const EdgeInsets.all(4.0),
        color: Colors.transparent,
        child: Icon(value ? Icons.check_circle : Icons.check_circle_outline,
            color: value ? selectedColor ?? AppColor.primary : unselectedColor ?? AppColor.gray[400]));
  }
}
